<template>
  <div>
    <div class="sheet_box">
      <div class="overstyle">
        <h3>官方榜</h3>
      </div>
      <div class="line"></div>
      <div class="card_container auto_box ranklist">
        <el-card class="box-card" v-for="(item, index) in hotrank" :key="index" shadow="never">
          <div slot="header" class="clearfix">
            <img v-lazy="item.coverImgUrl||item.coverUrl" width="100%" height="160" />
          </div>
          <div class="modefyStyle">
            <el-table
              stripe
              ref="singleTable"
              :data="sumlist[index]"
              highlight-current-row
              @current-change="handleCurrentChange"
              style="width: 100%"
              :show-header="false"
            >
              <el-table-column type="index"></el-table-column>
              <el-table-column property="name"></el-table-column>
            </el-table>
            <div class="lodemore">
              <p>
                <span>查看更多></span>
              </p>
            </div>
          </div>
        </el-card>
      </div>
    </div>
    <div class="sheet_box">
      <div class="overstyle">
        <h3>全球榜</h3>
      </div>
      <div class="line"></div>
      <div class="card_container auto_box">
        <div class="card" v-for="(o,index) in toplist" :key="index">
          <img v-lazy="o.coverImgUrl" width="160" height="160" />
          <p>{{ o.name }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'nav-rank',
  created () {
    //获取全部榜单
    this.$http.get("/api/toplist").then((res, err) => {
      if (err) {
        console.log(err.message)
      } else {
        this.hotrank = res.data.list.splice(0, 4)
        this.hotrank = this.hotrank.concat(res.data.artistToplist)
        this.toplist = res.data.list
      }
    })
    //获取歌手榜
    this.$http.get("/api/toplist/artist").then((res, err) => {
      if (err) {
        console.log(err.message)
      }
      this.singerRank = res.data.list.artists.splice(0, 8)
    })
    //3 0 2 1
    this.$http
      .get("/api/top/list?idx=3")
      .then((res, err) => {
        if (err) {
          console.log(err.message)
        } else {
          let temp = res.data.playlist.tracks
          this.sumlist.push(temp.splice(0, 8))
        }
      })
      .then(() => {
        this.$http.get("/api/top/list?idx=0").then((res, err) => {
          if (err) {
            return console.log(err.message)
          } else {
            let temp = res.data.playlist.tracks
            this.sumlist.push(temp.splice(0, 8))
          }
        })
      })
      .then(() => {
        this.$http.get("/api/top/list?idx=2").then((res, err) => {
          if (err) {
            return console.log(err.message)
          } else {
            let temp = res.data.playlist.tracks
            this.sumlist.push(temp.splice(0, 8))
          }
        })
      })
      .then(() => {
        this.$http.get("/api/top/list?idx=1").then((res, err) => {
          if (err) {
            return console.log(err.message)
          } else {
            let temp = res.data.playlist.tracks
            this.sumlist.push(temp.splice(0, 8))
            this.sumlist.push(this.singerRank)
            // console.log(this.sumlist);
          }
        })
      })
      .catch(err => {
        console.log(err.message)
      })
  },
  data () {
    return {
      hotrank: [],
      singerRank: [],
      surpluslist: [],
      sumlist: [],
      toplist: []
    }
  },
  methods: {
    setCurrent (row) {
      this.$refs.singleTable.setCurrentRow(row)
    },
    handleCurrentChange (val) {
      this.currentRow = val
    }
  }
};
</script>

<style lang="scss" scoped>
.dafult {
  padding: 0;
  background-color: red;
}
.sheet_box {
  width: 90%;
  margin: 0 auto;
  position: relative;
  user-select: none;
  .card {
    width: 180px;
    margin: 5px 0;
    height: 220px;
    float: left;
    cursor: pointer;
    img {
      box-sizing: border-box;
      border: 1px solid #000;
    }
    p {
      padding: 0;
      margin-top: 0;
      text-align: left;
      padding-left: 10px;
      font-size: 14px;
    }
  }
  .box-card {
    margin: 10px 14px 0 0px;
    width: 30%;
    float: left;
    margin-bottom: 10px;
  }
  .line {
    border-bottom: 1px solid #ccc;
    width: 100%;
    margin: 0 auto;
  }
  .auto_box {
    overflow: auto;
  }
  h3 {
    margin: 6px 0px;
    text-align: left;
    font-weight: normal;
    font-size: 18px;
  }
  .lodemore {
    background-color: #eee;
    height: 40px;
    text-align: right;
    line-height: 40px;
    font-size: 12px;
    color: rgba($color: #000, $alpha: 0.5);
    p {
      padding: 0;
      margin: 0;
      & > span {
        cursor: pointer;
      }
      & > span:hover {
        color: #000;
      }
    }
  }
}
</style>

<style lang="scss">
.auto_box.ranklist .el-card__header,
.auto_box.ranklist .el-card__body {
  border: 0;
  padding: 0;
}

.auto_box.ranklist .modefyStyle .el-table td,
.auto_box.ranklist .modefyStyle .el-table th {
  padding: 0px;
}

.auto_box.ranklist .modefyStyle .el-table .cell {
  line-height: 30px;
  padding: 0px;
  user-select: none;
}
.auto_box.ranklist .modefyStyle .el-table > .cell {
  text-align: center;
}
.auto_box.ranklist
  .modefyStyle
  .el-table--striped
  .el-table__body
  tr.el-table__row--striped.current-row
  td,
.auto_box.ranklist .modefyStyle .el-table__body tr.current-row > td {
  background-color: rgba($color: #aaa, $alpha: 0.6);
}

.auto_box.ranklist .modefyStyle .el-table__row > td:first-child > .cell {
  padding: 0px;
  text-align: center;
}
</style>